package com.dhl.deliver.service;

import com.dhl.deliver.utils.PostJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TimeService {


    public void postInfo(Date date) throws SchedulerException {

        SchedulerFactory factory=new StdSchedulerFactory();
        Scheduler scheduler=factory.getScheduler();
        JobDetail jobDetail= JobBuilder.newJob(PostJob.class)
                .withDescription("配送时间到了开始配送")
                .build();
        Trigger trigger=TriggerBuilder.newTrigger()
                .withDescription("启动配送")
                .startAt(date)
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();
        scheduler.scheduleJob(jobDetail,trigger);
        scheduler.start();
    }

}
